package com.ninong.ker.admin.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ninong.ker.admin.mapper.FwJobMapper;
import com.ninong.ker.admin.service.FwJobService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ninong.ker.admin.domain.FwJob;
import com.ninong.ker.admin.service.dto.FwJobDTO;


@Service
public class FwJobServiceImpl extends ServiceImpl<FwJobMapper, FwJob> implements FwJobService {

    @Override
    public PageInfo<FwJob> listPage(FwJobDTO dto) {
        PageHelper.startPage(dto.getCurrentPage(), dto.getPageSize());
        QueryWrapper<FwJob> query = new QueryWrapper<>();
        List<FwJob> fwJobs = baseMapper.selectList(query);
        return new PageInfo<FwJob>(fwJobs);
    }

    @Override
    public void delete(String[] ids) {
        List<String> idList = Arrays.asList(ids);
        idList.forEach(id -> {
            FwJob entity = new FwJob();
            entity.setId(id);
            entity.setDeleted(false);
            baseMapper.updateById(entity);
        });
    }

    @Override
    public void insert(FwJob entity) {
        //校验自行实现
        saveOrUpdate(entity);
    }

    @Override
    public FwJob get(String id) {
        FwJob entity = baseMapper.selectById(id);
        if (ObjectUtils.isEmpty(entity)) {
            entity = new FwJob();
        }
        return entity;
    }

}